package com.open.dome;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.open.dome.order.param.*;
import com.open.dome.until.HttpUntil;
import com.open.dome.until.SignUntil;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class Dome {

    /**
     * 时间 2025-02-20 13:01:18.583 签名规则发生了变化，请使用新的签名方式，即将本地数据库的mch_open表的sign_type字段改为1
     */
    private final static String appKey = "9WRvQGD5";
    private final static String secret = "1181dcbac4d39692ea3a3dbe9a48f0dc63ab22a7";
//   private final static  String url = "http://39.98.178.241:9002/open/api/";
 //  private final static  String url = "http://192.168.2.5:9002/open/api/"; demo
    private final static  String url = "http://192.168.138.1:9002/open/api/";

    public static void main(String[] args) {
//          cancelOrder("YYD30273184");
//          queryOrder("YYD30273185");
//        queryTrace("YYD30273184");
//        queryPrice();
//        createOrder();
//        createOrderV2();
//        queryPriceV2();

       // queryCJHYParam();
       // addAddress();

         testCreateWorkOrder();
       // testHistoryWorkOrder();
       // testGetWorkOrderConversation();
        //testFinishWorkOrder();
        //testExchangeWorkOrder();
        //testWorkOrderList();
    }

    /**
     * 测试商户工单列表
     */
    public static void testWorkOrderList(){
        WorkOrderPageForm workOrderPageForm = new WorkOrderPageForm();
        Long nowTime = System.currentTimeMillis();
        workOrderPageForm.setAppKey(appKey);
        workOrderPageForm.setTimestamp(nowTime);

        //填充参数
        WorkOrderPageParam workOrderPageParam = new WorkOrderPageParam();
        workOrderPageParam.setState(1);
        workOrderPageParam.setStartTime(LocalDate.of(2025, 2, 1));
        workOrderPageParam.setEndTime(LocalDate.of(2025, 2, 27));

        workOrderPageForm.setParam(JSONObject.toJSONString(workOrderPageParam));
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(workOrderPageParam), nowTime);
        workOrderPageForm.setSign(sign);

        //发请求
        String s = HttpUntil.doPostJson(url + "workOrderPage", JSONObject.toJSONString(workOrderPageForm));
        System.out.println("结束工单接口返回"+s);
    }

    /**
     * 测试回复工单
     */
    public static void testExchangeWorkOrder(){
        WorkOrderExchangeForm workOrderExchangeForm = new WorkOrderExchangeForm();
        Long nowTime = System.currentTimeMillis();
        workOrderExchangeForm.setAppKey(appKey);
        workOrderExchangeForm.setTimestamp(nowTime);

        //填充参数
        WorkOrderExchangeParam workOrderExchangeParam = new WorkOrderExchangeParam();
        workOrderExchangeParam.setWorkOrderId(20783L);
        workOrderExchangeParam.setContent("测试商家回复03-07");
        // 测试图片
        List<String> list = new ArrayList<>();
        list.add("https://longshengwangluo-1306719837.cos.ap-nanjing.myqcloud.com//dev/express/1719795290902.png");
        list.add("https://longshengwangluo-1306719837.cos.ap-nanjing.myqcloud.com//dev/express/1719795290902.png");
        workOrderExchangeParam.setImagesList(list);
        workOrderExchangeParam.setImagesList(list);

        workOrderExchangeForm.setParam(JSONObject.toJSONString(workOrderExchangeParam));
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(workOrderExchangeParam), nowTime);
        workOrderExchangeForm.setSign(sign);

        //发请求
        String s = HttpUntil.doPostJson(url + "workOrderExchange", JSONObject.toJSONString(workOrderExchangeForm));
        System.out.println("工单回复接口返回"+s);
    }

    /**
     * 测试结束工单
     */
    public static void testFinishWorkOrder(){
        FinishWorkOrderForm finishWorkOrderForm = new FinishWorkOrderForm();
        Long nowTime = System.currentTimeMillis();
        finishWorkOrderForm.setAppKey(appKey);
        finishWorkOrderForm.setTimestamp(nowTime);

        //填充参数
        FinishWorkOrderParam finishWorkOrderParam = new FinishWorkOrderParam();

        finishWorkOrderParam.setId(20821L);

        finishWorkOrderForm.setParam(JSONObject.toJSONString(finishWorkOrderParam));
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(finishWorkOrderParam), nowTime);
        finishWorkOrderForm.setSign(sign);

        //发请求
        String s = HttpUntil.doPostJson(url + "finishWorkOrder", JSONObject.toJSONString(finishWorkOrderForm));
        System.out.println("结束工单接口返回"+s);
    }

    /**
     * 测试获取工单会话记录
     */
    public static void testGetWorkOrderConversation(){
        WorkOrderConversationForm finishWorkOrderForm = new WorkOrderConversationForm();
        Long nowTime = System.currentTimeMillis();
        finishWorkOrderForm.setAppKey(appKey);
        finishWorkOrderForm.setTimestamp(nowTime);

        //填充参数
        WorkOrderConversationParam workOrderConversationParam = new WorkOrderConversationParam();
        workOrderConversationParam.setId(20783L);

        finishWorkOrderForm.setParam(JSONObject.toJSONString(workOrderConversationParam));
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(workOrderConversationParam), nowTime);
        finishWorkOrderForm.setSign(sign);

        //发请求
        String s = HttpUntil.doPostJson(url + "conversations", JSONObject.toJSONString(finishWorkOrderForm));
        System.out.println("获取工单会话接口返回"+s);
    }


    /**
     * 测试调用添加工单
     */
    public static void testCreateWorkOrder(){
        WorkOrderCreateForm workOrderCreateForm = new WorkOrderCreateForm();
        Long nowTime = System.currentTimeMillis();
        workOrderCreateForm.setAppKey(appKey);
        workOrderCreateForm.setTimestamp(nowTime);

        //填充参数
        OpenWorkOrderCreateDto openWorkOrderCreateDto = new OpenWorkOrderCreateDto();
        openWorkOrderCreateDto.setOrderId("DEVASD30271782");
        openWorkOrderCreateDto.setIsUrgent(1);
        openWorkOrderCreateDto.setTypeName("遗失理赔");
        openWorkOrderCreateDto.setSubmitterContent("远程调用测试");

        // 测试图片
        List<String> list = new ArrayList<>();
        list.add("https://longshengwangluo-1306719837.cos.ap-nanjing.myqcloud.com//dev/express/1719795290902.png");
        list.add("https://longshengwangluo-1306719837.cos.ap-nanjing.myqcloud.com//dev/express/1719795290902.png");
        openWorkOrderCreateDto.setSubmitterImages(list);
        workOrderCreateForm.setParam(JSONObject.toJSONString(openWorkOrderCreateDto));
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(openWorkOrderCreateDto), nowTime);
        workOrderCreateForm.setSign(sign);

        //发请求
        String s = HttpUntil.doPostJson(url + "createWorkOrder", JSONObject.toJSONString(workOrderCreateForm));
        System.out.println("创建工单接口返回"+s);
    }

    /**
     * 测试获取历史工单
     */
    public static void testHistoryWorkOrder(){
        WorkOrderHistoryForm workOrderHistoryForm = new WorkOrderHistoryForm();
        Long nowTime = System.currentTimeMillis();
        workOrderHistoryForm.setAppKey(appKey);
        workOrderHistoryForm.setTimestamp(nowTime);

        //填充参数
        WorkOrderHistoryParam workOrderHistoryParam = new WorkOrderHistoryParam();
        workOrderHistoryParam.setOrderId("DEVYYD30271491");

        workOrderHistoryForm.setParam(JSONObject.toJSONString(workOrderHistoryParam));
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(workOrderHistoryParam), nowTime);
        System.out.println("sign" + sign);
        workOrderHistoryForm.setSign(sign);

        //发请求
        String s = HttpUntil.doPostJson(url + "historyWorkOrderList", JSONObject.toJSONString(workOrderHistoryForm));
        System.out.println("获取历史工单接口返回"+s);
    }

    /**
     *查询超级货运参数
     */
    public static void queryCJHYParam(){
        OrderCjhyQueryForm orderCjhyQueryForm = new OrderCjhyQueryForm();
        long nowTime = System.currentTimeMillis();
        orderCjhyQueryForm.setAppKey(appKey);
        orderCjhyQueryForm.setTimestamp(nowTime);

        OrderCjhyQueryParam param = new OrderCjhyQueryParam();
        param.setSendProvince("广东省");
        param.setSendCity("广州市");
        param.setSendRegion("川汇区");
        param.setSendAddress("五一广场");
        param.setReceiveProvince("浙江省");
        param.setReceiveCity("杭州市");
        param.setReceiveRegion("上城区");
        param.setReceiveAddress("李沧区");
        param.setProductType("13");
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(param), nowTime);
        orderCjhyQueryForm.setSign(sign);
        orderCjhyQueryForm.setParam(JSONObject.toJSONString(param));
        System.out.println("param"+JSONObject.toJSONString(orderCjhyQueryForm, SerializerFeature.MapSortField));
        String s = HttpUntil.doPostJson(url + "queryCjhyParam", JSONObject.toJSONString(orderCjhyQueryForm));

        System.out.println("查价超级货运参数接口返回"+s);
    }

    public static void addAddress(){
        OrderAddressAddForm orderAddressAddForm = new OrderAddressAddForm();
        long nowTime = System.currentTimeMillis();
        orderAddressAddForm.setAppKey(appKey);
        orderAddressAddForm.setTimestamp(nowTime);
        OrderAddressAddParam orderAddressAddParam = new OrderAddressAddParam();
        orderAddressAddParam.setProvince("河南省");
        orderAddressAddParam.setCity("广州市");
        orderAddressAddParam.setRegion("川汇区");
        orderAddressAddParam.setAddress("五一广场");
        orderAddressAddParam.setName("开放平台测试名称");
        orderAddressAddParam.setPhone("13213347444");
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(orderAddressAddParam), nowTime);
        orderAddressAddForm.setSign(sign);
        orderAddressAddForm.setParam(JSONObject.toJSONString(orderAddressAddParam));
        System.out.println("param"+JSONObject.toJSONString(orderAddressAddForm, SerializerFeature.MapSortField));
        String s = HttpUntil.doPostJson(url + "addAddress", JSONObject.toJSONString(orderAddressAddForm));
        System.out.println("添加商家备案地址参数接口返回"+s);
    }
    /**
     * 查询价格
     */
    public static void  queryPrice(){
        QueryPriceForm queryPriceForm = new QueryPriceForm();
        long nowTime = System.currentTimeMillis();
        queryPriceForm.setAppKey(appKey);
        queryPriceForm.setTimestamp(nowTime);
        QueryPriceParam queryPriceParam = new QueryPriceParam();
        queryPriceParam.setChannelCategory(23);
        queryPriceParam.setCompanyCode("COM_CJHY");
        queryPriceParam.setSendProvince("河南省");
        queryPriceParam.setSendCity("周口市");
        queryPriceParam.setSendRegion("川汇区");
        queryPriceParam.setSendAddress("某某寄件地址测试");
        queryPriceParam.setSendName("寄件人名称");
        queryPriceParam.setSendPhone("13213347796");
        queryPriceParam.setPutProvince("河南省");
        queryPriceParam.setPutCity("周口市");
        queryPriceParam.setPutRegion("川汇区");
        queryPriceParam.setPutAddress("123");
        queryPriceParam.setPutName("李四");
        queryPriceParam.setPutPhone("17639417874");
        queryPriceParam.setStartTime("2025-02-14 15:00");
        queryPriceParam.setEndTime("2025-02-14 16:00");
        queryPriceParam.setGoodsPrice(500);
        queryPriceParam.setWeight(20d);
        queryPriceParam.setGoodsName("衣服");
        OrderCjhyFeeParam cjhyFeeParam = new OrderCjhyFeeParam();
        cjhyFeeParam.setId(22);
        cjhyFeeParam.setRequirements("02");
        cjhyFeeParam.setTakeDelivery("1");
        cjhyFeeParam.setBuildStart("");
        cjhyFeeParam.setBuildEnd("");


        queryPriceParam.setCjhyFeeParam(cjhyFeeParam);
        //新的签名方式
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(queryPriceParam), nowTime);
        queryPriceForm.setSign(sign);
        queryPriceForm.setParam(JSONObject.toJSONString(queryPriceParam));
        System.out.println("queryPriceParam"+JSONObject.toJSONString(queryPriceForm, SerializerFeature.MapSortField));
        String s = HttpUntil.doPostJson(url + "queryPrice", JSONObject.toJSONString(queryPriceForm));

        System.out.println("查价接口返回"+s);
    }
    /**
     * V2
     * 查询价格
     */
    public static void  queryPriceV2(){
        QueryPriceForm queryPriceForm = new QueryPriceForm();
        long nowTime = System.currentTimeMillis();
        queryPriceForm.setAppKey(appKey);
        queryPriceForm.setTimestamp(nowTime);

        QueryPriceParam queryPriceParam = new QueryPriceParam();
        queryPriceParam.setCompanyCode("COM_CJHY");
        queryPriceParam.setSendProvince("河南省");
        queryPriceParam.setChannelCategory(23);
        queryPriceParam.setSendCity("周口市");
        queryPriceParam.setSendRegion("川汇区");
        queryPriceParam.setSendAddress("某某寄件地址测试");
        queryPriceParam.setSendName("寄件人名称");
        queryPriceParam.setSendPhone("13213347796");
        queryPriceParam.setPutProvince("河南省");
        queryPriceParam.setPutCity("周口市");
        queryPriceParam.setPutRegion("川汇区");
        queryPriceParam.setPutAddress("万顺达广场");
        queryPriceParam.setPutName("收件人左右");
        queryPriceParam.setPutPhone("222222222222");
        queryPriceParam.setStartTime("2024-06-28 15:00");
        queryPriceParam.setEndTime("2024-06-28 18:00");
        queryPriceParam.setWeight(3d);
        queryPriceParam.setGoodsName("文件");
//        queryPriceParam.setGoodsPrice(600);
        OrderCjhyFeeParam cjhyFeeParam = new OrderCjhyFeeParam();
        cjhyFeeParam.setId(22);
        cjhyFeeParam.setRequirements("02");
        cjhyFeeParam.setTakeDelivery("1");
        cjhyFeeParam.setBuildStart("");
        cjhyFeeParam.setBuildEnd("");


        queryPriceParam.setCjhyFeeParam(cjhyFeeParam);
        //新的签名方式
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(queryPriceParam), nowTime);
        queryPriceForm.setSign(sign);
        queryPriceForm.setParam(JSONObject.toJSONString(queryPriceParam));
        String s = HttpUntil.doPostJson(url + "v2/queryPrice", JSONObject.toJSONString(queryPriceForm));
        System.out.println("查价接口返回"+s);
    }


    /**
     * 创建订单
     */
    public static void  createOrder(){

        OrderCreateForm orderCreateForm = new  OrderCreateForm();
        long nowTime = System.currentTimeMillis();
        orderCreateForm.setAppKey(appKey);
        orderCreateForm.setTimestamp(nowTime);

        OrderCreateParam orderCreateParam = new OrderCreateParam();
        orderCreateParam.setCompanyCode("COM_CJHY");
        orderCreateParam.setCompanyName("超级货运");
        orderCreateParam.setChannelCategory(23);
        orderCreateParam.setSendProvince("河南省");
        orderCreateParam.setSendCity("周口市");
        orderCreateParam.setSendRegion("川汇区");
        orderCreateParam.setSendAddress("某某寄件地址测试");
        orderCreateParam.setSendName("寄件人名称");
        orderCreateParam.setTransportType("12");
        orderCreateParam.setSendPhone("13213347796");
        orderCreateParam.setPutProvince("河南省");
        orderCreateParam.setPutCity("周口市");
        orderCreateParam.setPutRegion("川汇区");
        orderCreateParam.setPutAddress("万顺达广场");
        orderCreateParam.setPutName("收件人王道友");
        orderCreateParam.setPutPhone("120120120");

        orderCreateParam.setStartTime("2025-06-28 15:00");
        orderCreateParam.setEndTime("2025-06-28 18:00");
        orderCreateParam.setGoodsName("文件");
        orderCreateParam.setGoodsPrice(100);
        orderCreateParam.setNum(1);
//        orderCreateParam.setVolumeHeight(100);
//        orderCreateParam.setVolumeWidth(100);
//        orderCreateParam.setVolumeLong(100);
        orderCreateParam.setWeight(2d);
        orderCreateParam.setOpenOrderId("1212121");
        OrderCjhyFeeParam cjhyFeeParam = new OrderCjhyFeeParam();
        cjhyFeeParam.setId(22);
        cjhyFeeParam.setRequirements("02");
        cjhyFeeParam.setTakeDelivery("1");
        cjhyFeeParam.setBuildStart("");
        cjhyFeeParam.setBuildEnd("");
        orderCreateParam.setCjhyFeeParam(cjhyFeeParam);
        //新的签名方式
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(orderCreateParam), nowTime);

        orderCreateForm.setSign(sign);
        orderCreateForm.setParam(JSONObject.toJSONString(orderCreateParam));
        String s = HttpUntil.doPostJson(url + "createOrder", JSONObject.toJSONString(orderCreateForm));
        System.out.println("创建订单接口返回"+s);
    }
    /**
     * v2
     * 创建订单
     */
    public static void  createOrderV2(){

        OrderCreateFormV2 orderCreateForm = new OrderCreateFormV2();
        long nowTime = System.currentTimeMillis();
        orderCreateForm.setAppKey(appKey);
        orderCreateForm.setTimestamp(nowTime);

        OrderCreateParamV2 orderCreateParam = new OrderCreateParamV2();
        orderCreateParam.setCompanyCode("STO");
        orderCreateParam.setCompanyName("申通快递");
        orderCreateParam.setSendProvince("广东省");
        orderCreateParam.setSendCity("广州市");
        orderCreateParam.setSendRegion("天河区");
        orderCreateParam.setSendAddress("天河区");
        orderCreateParam.setSendName("张三");
        orderCreateParam.setChannelCategory(23);
        orderCreateParam.setTransportType("12");
        //channelid 新添加的字段
        // orderCreateParam.setChannelId(4102L);
        orderCreateParam.setChannelId(10412L);
        orderCreateParam.setSendPhone("17639417874");
        orderCreateParam.setPutProvince("浙江省");
        orderCreateParam.setPutCity("杭州市");
        orderCreateParam.setPutRegion("上城区");
        orderCreateParam.setPutAddress("李沧区");
        orderCreateParam.setPutName("李四");
        orderCreateParam.setPutPhone("17639417874");
        orderCreateParam.setStartTime("2024-06-28 15:00");
        orderCreateParam.setEndTime("2024-06-28 18:00");
        orderCreateParam.setGoodsName("文件");
        orderCreateParam.setGoodsPrice(100);
        orderCreateParam.setNum(1);
//        orderCreateParam.setVolumeHeight(100);
//        orderCreateParam.setVolumeWidth(100);
//        orderCreateParam.setVolumeLong(100);
        orderCreateParam.setWeight(5d);
        OrderCjhyFeeParam cjhyFeeParam = new OrderCjhyFeeParam();
        cjhyFeeParam.setId(22);
        cjhyFeeParam.setRequirements("01");
        cjhyFeeParam.setTakeDelivery("2");
        cjhyFeeParam.setBuildStart("");
        cjhyFeeParam.setBuildEnd("");
        orderCreateParam.setCjhyFeeParam(cjhyFeeParam);
        orderCreateParam.setOpenOrderId("1212121");
        //新的签名方式
        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(orderCreateParam), nowTime);

        orderCreateForm.setSign(sign);
        orderCreateForm.setParam(JSONObject.toJSONString(orderCreateParam));
        String s = HttpUntil.doPostJson(url + "v2/createOrder", JSONObject.toJSONString(orderCreateForm));
        System.out.println("创建订单接口返回"+s);
    }
    /**
     * 取消订单
     */
    public static void  cancelOrder(String orderId){
        OrderCancelForm orderCancelForm = new OrderCancelForm();
        long nowTime = System.currentTimeMillis();
        orderCancelForm.setAppKey(appKey);
        orderCancelForm.setTimestamp(nowTime);

        OrderCancelParam orderCancelParam = new OrderCancelParam();
        orderCancelParam.setOrderId(orderId);

        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(orderCancelParam), nowTime);

        orderCancelForm.setSign(sign);
        orderCancelForm.setParam(JSONObject.toJSONString(orderCancelParam));
        String s = HttpUntil.doPostJson(url + "cancelOrder", JSONObject.toJSONString(orderCancelForm));
        System.out.println("取消订单结果"+s);
    }
    /**
     * 查询订单
     */
    public static void  queryOrder(String orderId){
        OrderInfoForm orderCancelForm = new OrderInfoForm();
        long nowTime = System.currentTimeMillis();
        orderCancelForm.setAppKey(appKey);
        orderCancelForm.setTimestamp(nowTime);

        OrderInfoParam orderInfoParam = new OrderInfoParam();
        orderInfoParam.setOrderId(orderId);

        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(orderInfoParam), nowTime);

        orderCancelForm.setSign(sign);
        orderCancelForm.setParam(JSONObject.toJSONString(orderInfoParam));
        String s = HttpUntil.doPostJson(url + "queryOrder", JSONObject.toJSONString(orderCancelForm));
        System.out.println("查询订单详情结果"+s);

    }
    /**
     * 查询轨迹
     */
    public static void  queryTrace(String orderId){
        OrderTraceForm orderTraceForm = new OrderTraceForm();
        long nowTime = System.currentTimeMillis();
        orderTraceForm.setAppKey(appKey);
        orderTraceForm.setTimestamp(nowTime);

        OrderTraceParam orderTraceParam = new OrderTraceParam();
        orderTraceParam.setOrderId(orderId);

        String sign = SignUntil.generateSign(appKey, secret, JSONObject.toJSONString(orderTraceParam), nowTime);

        orderTraceForm.setSign(sign);
        orderTraceForm.setParam(JSONObject.toJSONString(orderTraceParam));
        String s = HttpUntil.doPostJson(url + "queryTrace", JSONObject.toJSONString(orderTraceForm));
        System.out.println("查询订单轨迹详情结果"+s);

    }
}
